﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using Microsoft.Extensions.Options;
using NetMicro.EventBus.Attributes;

namespace NetMicro.EventBus.Rulers
{
    public class EventHandlerNameRuler : IEventHandlerNameRuler
    {
        public EventHandlerNameRuler(IOptions<EventBusOptions> options)
        {
            Options = options;
        }

        private IOptions<EventBusOptions> Options { get; }

        public string GetName(Type eventType)
        {
            var name = eventType.GetCustomAttribute<EventHandlerAttribute>()?.Name;
            name ??= eventType.Name;

            return $"{name}.{Options.Value.Version}";
        }
    }
}
